﻿/*****************************************************************************
 
 Use of Ext is under the Ext JS license, for more information, 
 please visit http://extjs.com/products/license.php page. 
  
 You should confirm that you have read, understood and accept ethical criteria listed. 
 If not, see <http://www.mvcnext.com/license/>.
  
 Version: 1.0.0.0
 Website: http://www.mvcnext.com/
 
 For continued development and updates, visit http://yogsbreath.net
 
 ******************************************************************************/

using System;
using System.Web.UI.WebControls;
using System.Collections.Generic;
using System.Web.UI;
using System.Reflection;
using System.ComponentModel;

namespace MVCnExt.Web.UI.Ext
{
    public class ExtColorMenu : ExtMenu, ISubMenu
    {
        private List<ScriptReference> _references = new List<ScriptReference>();

        public override List<ScriptReference> GetScriptReferences()
        {
            _references.AddRange(base.GetScriptReferences());

            return _references;
        }

        public override IList<ScriptDescriptor> GetScriptDescriptors()
        {
            IList<ScriptDescriptor> list = base.GetScriptDescriptors();

            ScriptControlDescriptorBase desc = (ScriptControlDescriptorBase)list[0];

            desc.Type = "Ext.menu.ColorMenu";

            // date picker
            if (palette != null)
            {
                ScriptControlDescriptorBase descriptor = (ScriptControlDescriptorBase)palette.GetScriptDescriptors()[0];

                _references.AddRange(palette.GetScriptReferences());

                desc.AddPropertyBase("palette", descriptor.WriteScript(ScriptType.ConfigOnly));
            }

            return list;
        }


        #region Public Properties

        [PersistenceMode(PersistenceMode.InnerProperty)]
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
        public ExtColorPalette palette { get; set; }

        #endregion

        #region IMenuItem Members

        public string GetMenuItemScript()
        {
            ScriptControlDescriptorBase descriptor = (ScriptControlDescriptorBase)GetScriptDescriptors()[0];
            ExtScriptControlDescriptor config = new ExtScriptControlDescriptor("Ext.menu.ColorMenu", ID);
            config.AddPropertyBase("text", String.Format("'{0}'", text));
            config.AddPropertyBase("menu", descriptor.WriteScript(ScriptType.NewOnly));
            return config.WriteScript(ScriptType.ConfigOnly);
        }

        #endregion

        #region ISubMenu Members

        public String text { get; set; }

        #endregion
    }
}
